package xeroxware.framework.xplatform;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.tobesoft.xplatform.data.PlatformData;
import com.tobesoft.xplatform.tx.HttpPlatformRequest;
import com.tobesoft.xplatform.tx.PlatformException;

import xeroxware.framework.UiAdaptor;

/**
 * <pre>
 * XplatformAdaptor
 * </pre>
 * 
 * @since 2013. 1. 9.
 * @author XEROXER
 */
public class XplatformAdaptor implements UiAdaptor {

	private static final Logger logger = LoggerFactory.getLogger(XplatformAdaptor.class);

	public Object convert(HttpServletRequest request) throws Exception {

		HttpPlatformRequest platfromRequest = null;
		PlatformData platformData = null;
		XplatformDTO xplatformDTO = null;

		try {
			platfromRequest = new HttpPlatformRequest(request);
			platfromRequest.receiveData();

			platformData = platfromRequest.getData();

			logger.debug("========== Request PlatformData ==========\n{}", platformData.saveXml());

			xplatformDTO = new XplatformDTO(platformData);
		} catch (PlatformException e) {
			throw e;
		} catch (Exception e) {
			throw e;
		}

		return xplatformDTO;
	}

	public Class<?> getModelName() {
		return new XplatformDTO().getClass();
	}
}
